var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r,
    s = t("TearImgTool"),
    c = t("TextureAssembler");
cc.renderer.renderEngine;
(function (t) {
    t[(t.Cut = 0)] = "Cut";
    t[(t.Stretch = 1)] = "Stretch";
})(r || (r = {}));
var p = new cc.Vec2(),
    l = new cc.Mat4(),
    d = cc._decorator,
    u = d.ccclass,
    h = (d.inspector, d.executeInEditMode),
    f = (d.mixins, d.property),
    y = (function (t) {
        i(e, t);
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            e._texture = null;
            e._type = 0;
            e.editing = !1;
            e._polygon = [];
            e._assembler = null;
            return e;
        }
        Object.defineProperty(e.prototype, "texture", {
            get: function () {
                return this._texture;
            },
            set: function (t) {
                this._texture = t;
                var e = -t.width / 2,
                    o = -t.height / 2,
                    a = t.height / 2,
                    i = t.width / 2;
                this.polygon = [cc.v2(e, o), cc.v2(i, o), cc.v2(i, a), cc.v2(e, a)];
                this._updateMaterial();
            },
            enumerable: !1,
            configurable: !0
        });
        Object.defineProperty(e.prototype, "type", {
            get: function () {
                return this._type;
            },
            set: function (t) {
                this._type = t;
                this.setVertsDirty();
            },
            enumerable: !1,
            configurable: !0
        });
        Object.defineProperty(e.prototype, "polygon", {
            get: function () {
                return this._polygon;
            },
            set: function (t) {
                this._polygon = t;
                this._updateVerts();
            },
            enumerable: !1,
            configurable: !0
        });
        e.prototype.onLoad = function () {
            this.node._hitTest = this._hitTest.bind(this);
        };
        e.prototype.start = function () {
            var t = this;
            this.node.on(
                cc.Node.EventType.TOUCH_START,
                function () {
                    console.log("click texture plus");
                },
                this
            );
            this.node.on(
                cc.Node.EventType.TOUCH_MOVE,
                function (e) {
                    t.node.x += e.getDeltaX();
                    t.node.y += e.getDeltaY();
                },
                this
            );
        };
        e.prototype._updateVerts = function () {
            this.setVertsDirty();
        };
        e.prototype._updateMaterial = function () {
            var t = this._texture,
                e = this.getMaterial(0);
            if (e) {
                void 0 !== e.getDefine("USE_TEXTURE") && e.define("USE_TEXTURE", !0);
                e.setProperty("texture", t);
            }
            this.setVertsDirty();
        };
        e.prototype._validateRender = function () {};
        e.prototype._resetAssembler = function () {
            (this._assembler = new c.default()).init(this);
            this._updateColor();
            this.setVertsDirty();
        };
        e.prototype._hitTest = function (t) {
            var e = this.node,
                o = p;
            e._updateWorldMatrix();
            if (!cc.Mat4.invert(l, e._worldMatrix)) return !1;
            cc.Vec2.transformMat4(o, t, l);
            return s.default.isInPolygon(o, this.polygon);
        };
        e.Type = r;
        n([f(cc.Texture2D)], e.prototype, "_texture", void 0);
        n([f(cc.Texture2D)], e.prototype, "texture", null);
        n([f({type: cc.Enum(r), serializable: !0})], e.prototype, "type", null);
        n([f(cc.Boolean)], e.prototype, "editing", void 0);
        n([f({type: [cc.Vec2], serializable: !0})], e.prototype, "_polygon", void 0);
        n([f({type: [cc.Vec2], serializable: !0})], e.prototype, "polygon", null);
        return n([u, h], e);
    })(cc.RenderComponent);
o.default = y;
